<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>活动管理</title>
<%@ include file="/module/js.jsp"%>
<script type="text/javascript">
	$(document).ready(function(){

	    //加载表格分页数据
        $('#dg').datagrid({
            url:'${basePath}/partyActivity/listData?hdType=${hdType}',
            pagination:true,
            collapsible:true,
			method:'post',
            remoteSort:true,
            columns:[[
                {field:'hDID',checkbox:true,width:120,align:'center'},
                {field:'hDMC',title:'活动名称',width:150,align:'center',formatter:modify_formater},
                {field:'hDRQ',title:'活动日期',width:200,align:'center',formatter:formatDate},
                {field:'hDSJ',title:'活动时间',width:200,align:'center'},
                {field:'hDDD',title:'活动地点',width:300,align:'center'},
                {field:'hDZT',title:'活动主题',width:300,align:'center'}
            ]]
        });

        //设置固定活动日弹出层
        $("#div1").dialog({
            width : '450px',
            height : 'auto',
            bgiframe : true,
            modal : true,
            draggable : true,
            resizable : false,
            title : '活动固定日设置',
            autoOpen : false,
            buttons : {
                '取消' : function() {
                    $(this).dialog('close');
                },
                '确定' : function() {
                    $.ajax({
                        type: "GET",
                        url: "${basePath}/partyActivity/setPartyFixedDateActivityDay",
                        data: {partyFixedDateActivityDay:$("#partyFixedDateActivityDay").val()},
                        dataType: "json",
                        success: function(data){
                            if(data==1){
                                alert('设置成功');
                                window.location.href = '${basePath}/partyActivity/list?hdType=${hdType}'
                                //$('#dg').datagrid('reload');
                            }else{
                                alert('设置失败，请联系管理员');
                            }
                        },
                        complete: function(){
                            $("#div1").dialog('close');
                        }
                    });
                }
            }
        });

        //点击弹出层
        $("#daySet").click(function(){
            $('#div1').dialog('open');
        });


        //跳转到添加页面
        $("#btnAdd").click(function(){
            $("#partyActivityForm").attr("action","${basePath}/partyActivity/preadd?hdType=${hdType}");
            $("#partyActivityForm").submit();
        });
        
        $('#btnExport')
		.on(
				'click',
				function() {
					layer
							.confirm(
									"您确定要导出吗?",
									{
										icon : 3,
										title : '提示',
										skin : 'layer-ext-moon'
									},
									function(index) {
										layer.closeAll('dialog');//解决导出成功后提示框不关闭的问题
										
										 $("#partyActivityForm").attr("action","${basePath}/partyActivity/exportPartyActivity?hdType=${hdType}");
								         $("#partyActivityForm").submit();
									});
				});

        //查询
        $("#btnQuery").click(function(){
            $('#dg').datagrid('load',{
                hDMC: $('#hDMC').val(),
                hDZT: $('#hDZT').val(),
                bdate: $('#bdate').val(),
                edate: $('#edate').val()
            });
        });


        //删除
        $("#btnDelete").click(function(){
            var itemList = $("#dg");
            var sels = $("#dg").datagrid("getSelections");
            var idList = new Array();
            var count = 0;
            for(var i in sels){
                idList.push(sels[i].id);
                count++;
            }
            if (count == 0) {
                alert("请选择一条记录 ");
                return false;
            }
            
            layer
			.confirm("您是否删除当前选中数据信息",{
						icon : 3,
						title : '提示',
						skin : 'layer-ext-moon'
					},
					function(index) {
						$("#idList").val(idList);
						 $("#partyActivityForm").attr("action","${basePath}/partyActivity/delete");
				         $("#partyActivityForm").submit();
					},
					function(
							index) {
						layer
								.close(index);
					});
        });

	});

	//修改
    function modify_formater(value, row, index) {
        return "<a href='${basePath}/partyActivity/info?hdType=${hdType}&id=" + row.hDID + "'>" + value + "</a>";
    }

    function formatDate(value){
        var date=new Date(value);
        return date.Format("yyyy-MM-dd");
    }


    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "H+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }


    if ("${msg}" != "") {
        layer.alert("${msg}", {
            icon : 6
        });
    }

</script>
</head>
<body >
	<form action="#" name="partyActivityForm" id="partyActivityForm" method="post">
        <input type="hidden" name="hdType" id="hdType" value="${hdType}"/>
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td>
                    <input type="button" id="btnQuery" autocomplete="off"  value="查询"
                           class="inputButton" />
                </td>
                <c:if test="${hdType=='1'}">
                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DJHD_GDRHD\")%>"
                                   key="add">
                        <td>
                            <input type="button" id="btnAdd" value="添 加" autocomplete="off"
                                   class="inputButton" />
                        </td>
                    </kl:permission>

                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DJHD_GDRHD\")%>"
                                   key="delete">
                        <td>
                            <input type="button" id="btnDelete" value="删除"
                                   class="inputButton" />
                        </td>
                    </kl:permission>
                </c:if>

                <c:if test="${hdType=='2'}">
                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DJHD_SQZY\")%>"
                                   key="add">
                        <td>
                            <input type="button" id="btnAdd" value="添 加" autocomplete="off"
                                   class="inputButton" />
                        </td>
                    </kl:permission>

                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DJHD_SQZY\")%>"
                                   key="delete">
                        <td>
                            <input type="button" id="btnDelete" value="删除"
                                   class="inputButton" />
                        </td>
                    </kl:permission>
                </c:if>

                <c:if test="${hdType=='3'}">
                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_XCSX_GLXX\")%>"
                                   key="add">
                        <td>
                            <input type="button" id="btnAdd" value="添 加" autocomplete="off"
                                   class="inputButton" />
                        </td>
                    </kl:permission>

                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_XCSX_GLXX\")%>"
                                   key="delete">
                        <td>
                            <input type="button" id="btnDelete" value="删除"
                                   class="inputButton" />
                        </td>
                    </kl:permission>
                </c:if>

                <c:if test="${hdType=='4'}">
                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DFLZ_FXHCL\")%>"
                                   key="add">
                        <td>
                            <input type="button" id="btnAdd" value="添 加" autocomplete="off"
                                   class="inputButton" />
                        </td>
                    </kl:permission>

                    <kl:permission permisstionList="${permisstionList}"
                                   currentUser="${_login_console_user}"
                                   currentCatalogId="<%=CatalogUtils.getCatalogId(\"ZHDJ_DFLZ_FXHCL\")%>"
                                   key="delete">
                        <td>
                            <input type="button" id="btnDelete" value="删除"
                                   class="inputButton" />
                        </td>
                    </kl:permission>
                </c:if>


			 	<td><input type="button" id="btnExport" value="导出"
					class="inputButton" /></td>
                <c:if test="${hdType=='1'}">
                    <td>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;活动固定日为每月【${partyFixedDateActivityDay}】号
                        <input type="button" id="daySet" value="设置"
                               class="inputButton" />
                    </td>
                </c:if>
			</tr>
		</table>
		<table cellpadding="1" cellspacing="1">
			<tr>
				<td>活动名称：</td>
				<td>
                    <input type="text" id="hDMC" name="hDMC" value="" class="inputText2"/>
                </td>
				<td>活动主题：</td>
                <td>
                    <input type="text" id="hDZT" name="hDZT" value="" class="inputText2" />
                </td>
				<td>活动日期：</td>
				<td>
                    从
                    <input name="bdate" id="bdate"  autocomplete="off"
                           class="Wdate required inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                    到
                    <input name="edate" id="edate" autocomplete="off"
                           class="Wdate required inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
                </td>
			</tr>
		</table>
		<br/>
		<table id="dg"></table>

        <div id="div1" style="display: none;">
            <table cellpadding="0" style="padding-top: 20px;" cellspacing="0" border="0" class="table-border" width="100%">
                <tr>
                    <td class="table-titleTD" style="width: 30%"><font
                            style="color: red;">*</font>日期：</td>
                    <td class="table-contentTD" style="width: 70%">
                        每月的<select name="partyFixedDateActivityDay" id="partyFixedDateActivityDay" class="selectList">
                        <c:forEach var="i" begin="1" end="28">
                            <option value="${i}">${i}</option>
                        </c:forEach>
                    </select>号</td>
                </tr>
            </table>
        </div>

	</form>
</body>
</html>
